# -*- coding: utf-8 -*-
# ㊎ Author : XMZ
# ㊍ Time : 2021/10/14 14:51
# ㊌ File : formula -> authorization.py
# ㊋ IDE :  PyCharm
# ㊏ 
import os
import sys
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
from rest_framework_simplejwt.views import TokenObtainPairView


class FormulaTokenObtainPairSerializer(TokenObtainPairSerializer):
    def create(self, validated_data):
        pass

    def update(self, instance, validated_data):
        pass

    def validate(self, attrs):
        data = super().validate(attrs)

        refresh = self.get_token(self.user)

        data['username'] = self.user.username
        data['mobile'] = self.user.mobile
        data['refresh'] = str(refresh)
        data['access'] = str(refresh.access_token)

        return {"code": "200", "msg": "ok", "data": data}


class FormulaTokenObtainPairView(TokenObtainPairView):
    serializer_class = FormulaTokenObtainPairSerializer
